package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.items.entity.Xzwrz;
import com.gfxy.modules.items.entity.teachingresult.TeachingResultContent;
import com.gfxy.modules.items.mapper.XzwrzMapper;
import com.gfxy.modules.items.service.IXzwrzService;
import com.gfxy.modules.items.vo.XzwrzMemberPage;
import com.gfxy.modules.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 行职委任职
 * @Author: jeecg-boot
 * @Date:   2021-10-01
 * @Version: V1.0
 */
@Service
public class XzwrzServiceImpl extends AbstractProjectServiceImpl<XzwrzMapper, Xzwrz> implements IXzwrzService {
	protected int memberCellNum = 3;

	@Override
	protected void pass(String id, String isPass) {

	}

	@Override
	protected String[] getMemberArray(Row row) {
		String nameStrs = ExcelUtil.formatCell(row.getCell(memberCellNum));
		return nameStrs.split(memberNameSeparator);
	}

	@Override
	protected Xzwrz getOneProject(Row row) {
		String date = ExcelUtil.formatCell(row.getCell(0));
		String classess  = ExcelUtil.formatCell(row.getCell(1));
		String projectName = ExcelUtil.formatCell(row.getCell(2));
		Xzwrz xzwrz = new Xzwrz();
		xzwrz.setDate(date);
		xzwrz.setClassess(translateClassess(classess));
		xzwrz.setProjectName(projectName);
		xzwrz.setIsPass(0);
		xzwrz.setTotalScore(this.getTotalScore(xzwrz));
		return xzwrz;
	}
	private int translateClassess(String Classess){
		if(Classess == null || Classess.equals("")){
			return 0;
		} else if(Classess.equals("国家级")){
			return 1;
		} else if(Classess.equals("省级")){
			return 2;
		} else if(Classess.equals("市级")){
			return 3;
		} else {
			return 0;
		}
	}

	@Override
	public Double getTotalScore(Xzwrz xzwrz) {
		double result = 0.0;
		int classess = xzwrz.getClassess();
		if(classess == 1){
			result = 80;
		} else if(classess == 2 ) {
			result = 50;
		} else if(classess == 3 ) {
			result = 20;
		}
		return result;
	}

	@Override
	public IPage<XzwrzMemberPage> getXzwrzMemberPageListByYear(String date, Integer pageNo, Integer pageSize) {
		Page<XzwrzMemberPage> page = new Page<>(pageNo,pageSize);
		return page.setRecords(this.baseMapper.selectXzwrzMemberPageListByYear(date));
	}

	@Override
	public List<XzwrzMemberPage> getXzwrzMemberPageListByYear(String date) {
		return this.baseMapper.selectXzwrzMemberPageListByYear(date);
	}

	@Override
	protected List<TeachingResultContent> createTeachingResultContent(Xzwrz jxcg)  {

		List<TeachingResultContent> result = new ArrayList<>();

		// 类型
		TeachingResultContent classTeachingResultContent = new TeachingResultContent();
		classTeachingResultContent.setType(1);
		classTeachingResultContent.setLevel(jxcg.getClassess());

		try {
			classTeachingResultContent.setValue(dictTranslater.getDictValue(XzwrzMemberPage.class, "classess", String.valueOf(jxcg.getClassess())));
			result.add(classTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		return result;
	}

}
